<?php declare(strict_types=1);

namespace PinWuYun\domain\manager;


use Illuminate\Database\Capsule\Manager;
use linkcache\Cache;

/**
 * Created: by zhiJie
 * Date: 2021/7/1
 */
class ManagerApp
{
    public function init()
    {
        $config = [
            //默认使用的缓存驱动
            'default' => 'files',
            //当前缓存驱动失效时，使用的备份驱动
            'fallback' => 'files',
            'memcache' => [
                'servers' => [
                    ['host' => '127.0.0.1', 'port' => 11211, 'weight' => 1, 'persistent' => true, 'timeout' => 1, 'retry_interval' => 15, 'status' => true],
                ],
                'compress' => ['threshold' => 2000, 'min_saving' => 0.2],
            ],
            'memcached' => [
                'servers' => [
                    ['host' => '127.0.0.1', 'port' => 11211, 'weight' => 1],
                ],
                //参考 Memcached::setOptions
                'options' => [],
            ],
            'redis' => [
                'host' => '127.0.0.1',
                'port' => 6379,
                'password' => '',
                'database' => '',
                'timeout' => ''
            ],
            'ssdb' => [
                'host' => '127.0.0.1',
                'port' => 8888,
                'password' => '',
                'timeoutms' => ''
            ],
        ];
        Cache::setConfig($config);
    }

    /**
     * 注册laravel DB
     */
    public static function registerDb(): void
    {
        $capsule = new Manager();
        $capsule->addConnection([
            'driver'    => 'mysql',
            'host'      => '127.0.0.1',
            'database'  => 'you_zan',
            'username'  => 'root',
            'password'  => 'root123',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        ]);
        $capsule->setAsGlobal();
        $capsule->bootEloquent();
    }
}
